package chapters15_bingfa.chapters15_1;

/**
 * Created by xinxuchu on 2020/1/25.
 *
 * 内存可见性:多个线程可以共享访问和操作相同的变量，但一个线程对一个共享变量的修改，
 * 另一个线程不一定马上就能看到，甚至永远也看不到。
 */
public class VisibilityDemo {

    private static boolean shutdown = false;

    static class HelloThread  extends Thread{

        private int num = 0;
        @Override
        public void run(){

            while (!shutdown){
                //todo
                System.out.println(num++);
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {

        new HelloThread().start();
        Thread.sleep(1000);
        shutdown = true;
        System.out.println("exit main");
    }

}
